﻿using AutoFlatnessTest.ViewModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace AutoFlatnessTest
{
    /// <summary>
    /// WinInput.xaml 的交互逻辑
    /// </summary>
    public partial class WinInput : HandyControl.Controls.Window
    {
        public WinInputVModel VModel = new WinInputVModel();

        public delegate void ClickOkEventHandler(object sender, ClickOkEventInfo okInfo);
        public event ClickOkEventHandler ClickOk;

        public WinInput()
        {
            InitializeComponent();

            this.DataContext = VModel;
        }

        private void but_close(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
            this.Close();
        }

        private void but_ok(object sender, RoutedEventArgs e)
        {
            if (ClickOk != null)
            {
                ClickOkEventInfo clickOkEventInfo = new ClickOkEventInfo();
                clickOkEventInfo.InputTxt = VModel.InputTxt;

                ClickOk(this, clickOkEventInfo);

                if (!clickOkEventInfo.IsOk)
                {
                    if (!string.IsNullOrEmpty(clickOkEventInfo.ErrInfo))
                    {
                        MessageBox.Show(clickOkEventInfo.ErrInfo);
                    }
                    return;
                }
            }

            DialogResult = true;
            this.Close();

        }
    }

    public class ClickOkEventInfo
    {
        public string InputTxt { get; set; }
        public bool IsOk { get; set; } = true;
        public string ErrInfo { get; set; } = string.Empty;
    }

}
